<template>
    <div v-for="(item, i) in list" :key="i" :ref="el => { if (el) {divs[i] = el;log(el)} }">
        {{ item }}
    </div>
</template>

<script>
    import {
        ref,
        reactive,
        onBeforeUpdate
    } from 'vue'

    export default {
        setup() {
            const list = reactive([1, 2, 3])
            const divs = ref([])
const {log}=console
            // 确保在每次更新之前重置ref
            onBeforeUpdate(() => {
                divs.value = []
            })


            return {
                list,
                divs,
                log
            }
        }
    }
</script>